package edu.gdpu.memory.stack;

/**
 * @author mazebin
 * @date 2021年 07月14日 16:56:11
 * 演示线程死锁
 *
 */
public class ThreadDeadLockTest {
    static A  a= new A();
    static B b = new B();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (a){
                try {
                    Thread.sleep(2000);
                } catch ( InterruptedException e ) {
                    e.printStackTrace();
                }
                synchronized (b){
                    System.out.println("我获得了A和B");
                }
            }
        }).start();
        try {
            Thread.sleep(1000);
        } catch ( InterruptedException e ) {
            e.printStackTrace();
        }
        new Thread(()->{
            synchronized (b){
                synchronized (a){
                    System.out.println("我获得了A和B");
                }
            }
        }).start();;

    }
}
class A{

}
class B{

}
